﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using QLT_BLL;
using QLT_Public;
using System.Diagnostics;

namespace GiaoDien
{
    public partial class FrmMain : RibbonForm
    {
        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }
        public void LoadForm()
        {
            //tất cả các chức năng cho falas,chỉ đăng nhập là ko cho false,nên ko cần cho vào đây
            //Phần Hệ thống
            dangxuatbarButtonItem11.Enabled = false;
            doimatkhaubarButtonItem12.Enabled = false;
            NhomNguoiDungbarButtonItem13.Enabled = false;
            CapNhatQuyenHanbarButtonItem3.Enabled = false;
            saoluubarButtonItem14.Enabled = false;
            phuchoibarButtonItem15.Enabled = false;
            NhatKySuDungbarButtonItem2.Enabled = false;
            iExit.Enabled = true;
            ////Cập nhật
            hosonvbarButtonItem1.Enabled = false;
            dmthuocbarButtonItem2.Enabled = false;
            loaithuocbarButtonItem1.Enabled = false;
            hdbanbarButtonItem2.Enabled = false;
            hdnhapbarButtonItem10.Enabled = false;
            barButtonCTHDBH.Enabled = false;
            barButtonCTHDN.Enabled = false;
            bbi_CapNhatKhachHang.Enabled = false;

            ////tìm kiếm
            tkThuocbarButtonItem3.Enabled = false;
            tkNVbarButtonItem5.Enabled = false;
            tkKhachHangbarButtonItem2.Enabled = false;

            ////thống kê báo cáo
            barButtonTKLoaiThuoc.Enabled = false;
            TKeThuocQuaHanbarButton.Enabled = false;
            ThongKeDoanhThuTheoThangbarButtonItem1.Enabled = false;
            TKeThuocBanTheongaybarButtonItem8.Enabled = false;
            TKeThuocNhapbarButton.Enabled = false;
            ////menu bên trái
            DMThuocItem.Enabled = false;
            HSNVItem.Enabled = false;
            TC_TenThuocItem.Enabled = false;
            TC_NVItem.Enabled = false;
        }
        public void Load_QuanLy()
        {
            ////Phần Hệ thống
            dangnhapbarButtonItem10.Enabled = false;
            dangxuatbarButtonItem11.Enabled = true;
            doimatkhaubarButtonItem12.Enabled = true;
            NhomNguoiDungbarButtonItem13.Enabled = true;
            CapNhatQuyenHanbarButtonItem3.Enabled = true;
            saoluubarButtonItem14.Enabled = true;
            phuchoibarButtonItem15.Enabled = true;
            NhatKySuDungbarButtonItem2.Enabled = true;
            iExit.Enabled = true;
            ////Cập nhật
            hosonvbarButtonItem1.Enabled = true;
            dmthuocbarButtonItem2.Enabled = true;
            loaithuocbarButtonItem1.Enabled = true;
            hdbanbarButtonItem2.Enabled = true;
            hdnhapbarButtonItem10.Enabled = true;
            barButtonCTHDBH.Enabled = true;
            barButtonCTHDN.Enabled = true;
            bbi_CapNhatKhachHang.Enabled = true;
            ////tìm kiếm
            tkThuocbarButtonItem3.Enabled = true;
            tkNVbarButtonItem5.Enabled = true;
            tkKhachHangbarButtonItem2.Enabled = true;
            ////thống kê báo cáo
            barButtonTKLoaiThuoc.Enabled = true;
            TKeThuocQuaHanbarButton.Enabled = true;
            ThongKeDoanhThuTheoThangbarButtonItem1.Enabled = true;
            TKeThuocBanTheongaybarButtonItem8.Enabled = true;
            TKeThuocNhapbarButton.Enabled = true;
            ////menu bên trái
            DMThuocItem.Enabled = true;
            HSNVItem.Enabled = true;
            TC_TenThuocItem.Enabled = true;
            TC_NVItem.Enabled = true;
        }
        public void Load_NhanVien()
        {
            //Phần Hệ thống
            dangnhapbarButtonItem10.Enabled = false;
            dangxuatbarButtonItem11.Enabled = true;
            doimatkhaubarButtonItem12.Enabled = true;
            iExit.Enabled = true;
            ////Cập nhật
            hosonvbarButtonItem1.Enabled = true;
            dmthuocbarButtonItem2.Enabled = true;
            loaithuocbarButtonItem1.Enabled = true;
            hdbanbarButtonItem2.Enabled = true;
            hdnhapbarButtonItem10.Enabled = true;
            barButtonCTHDBH.Enabled = true;
            barButtonCTHDN.Enabled = true;
            bbi_CapNhatKhachHang.Enabled = true;

            ////tìm kiếm
            tkThuocbarButtonItem3.Enabled = true;
            tkNVbarButtonItem5.Enabled = true;
            tkKhachHangbarButtonItem2.Enabled = true;

            ////thống kê báo cáo
            barButtonTKLoaiThuoc.Enabled = true;
            TKeThuocQuaHanbarButton.Enabled = true;
            ThongKeDoanhThuTheoThangbarButtonItem1.Enabled = true;
            TKeThuocBanTheongaybarButtonItem8.Enabled = true;
            TKeThuocNhapbarButton.Enabled = true;
            //menu bên trái
            DMThuocItem.Enabled = true;
            //HSNVItem.Enabled = true;
            TC_TenThuocItem.Enabled = true;
            //TC_NVItem.Enabled = true;
        }

        private void dmthuocbarButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_Thuoc f = new uc_Thuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void loaithuocbarButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_LoaiThuoc f = new uc_LoaiThuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void hosonvbarButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_HSNhanVien f = new uc_HSNhanVien();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void hdbanbarButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_HoaDonBH f = new uc_HoaDonBH();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void hdnhapbarButtonItem10_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_HoaDonNhap f = new uc_HoaDonNhap();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void barButtonCTHDBH_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_CTHoaDonBH f = new uc_CTHoaDonBH();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void barButtonCTHDN_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_CTHoaDonNhap f = new uc_CTHoaDonNhap();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void tkThuocbarButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TKThuoc f = new uc_TKThuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void tkNVbarButtonItem5_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TKNhanVien f = new uc_TKNhanVien();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void tkKhachHangbarButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_TKKhachHang f = new uc_TKKhachHang();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }
        public void GetLoad(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        private void dangnhapbarButtonItem10_ItemClick(object sender, ItemClickEventArgs e)
        {
            frm_DangNhap f = new frm_DangNhap();
            f.MyGetLoad = new frm_DangNhap.GetInt(GetLoad);
            f.ShowDialog();
        }

        private void doimatkhaubarButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
        {
            frm_ThayDoiMK f = new frm_ThayDoiMK();
            f.ShowDialog();
        }

        private void barButtonTKLoaiThuoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_LoaiThuoc f = new uc_ThongKe_LoaiThuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void TKeThuocQuaHanbarButton_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_ThuocQuaHan f = new uc_ThongKe_ThuocQuaHan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                // txt_Load==1 thì là gọi hàm Load_Quản lý
                Load_QuanLy();
            }
            if (txt_Load.Text == "2")
            {
                //
                Load_NhanVien();
            }
        }
        NhatKy_Bll nhatKy_bll = new NhatKy_Bll();
        private void dangxuatbarButtonItem11_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn đăng xuất khỏi hệ thống không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {

                txt_Load.Text = "0";
                string d = DateTime.Now.ToString();
                NhatKy_Public nk = new NhatKy_Public();
                nk.TaiKhoan = tg.TaiKhoan;
                nk.NgayGio = d;
                nk.DoiTuong = tg.DoiTuong;
                nk.HanhDong = "Đăng Xuất";
                nk.MoTa = "Đăng xuất khỏi hệ thống";
                nhatKy_bll.insert_NhatKy(nk, nk, nk, nk, nk);
                FrmMain_Load(sender,e);
                dangnhapbarButtonItem10.Enabled = true;
                
            }
               
        }

        private void CapNhatQuyenHanbarButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_QuyenHan f = new uc_QuyenHan();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void NhomNguoiDungbarButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NhomNguoiDung f = new uc_NhomNguoiDung();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }
        Class_TrungGian tg = new Class_TrungGian();
        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát chương trình không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                string d = DateTime.Now.ToString();
                NhatKy_Public nk = new NhatKy_Public();
                nk.TaiKhoan = tg.TaiKhoan;
                nk.NgayGio = d;
                nk.DoiTuong = tg.DoiTuong;
                nk.HanhDong = "Đăng Xuất";
                nk.MoTa = "Đăng xuất khỏi hệ thống";
                nhatKy_bll.insert_NhatKy(nk,nk,nk,nk,nk);
                System.Windows.Forms.Application.Exit();

            }
        }

        private void NhatKySuDungbarButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_NhatKy f = new uc_NhatKy();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            txt_Load.Hide();
            LoadForm();
        }

        private void TKeThuocBanTheongaybarButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_ThuocBan_TheoNgay f = new uc_ThongKe_ThuocBan_TheoNgay();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void ThongKeDoanhThuTheoThangbarButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_DoanhThu_TheoThang f = new uc_ThongKe_DoanhThu_TheoThang();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void MayTinhbarButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            Process.Start("C:\\Windows\\system32\\calc.exe");
        }

        private void saoluubarButtonItem14_ItemClick(object sender, ItemClickEventArgs e)
        {
            frm_SaoLuu f = new frm_SaoLuu();
            f.ShowDialog();
        }

        private void DMThuocItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            uc_Thuoc f = new uc_Thuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void TC_TenThuocItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            uc_TKThuoc f = new uc_TKThuoc();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void TC_NVItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            uc_TKNhanVien f = new uc_TKNhanVien();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void HSNVItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            uc_HSNhanVien f = new uc_HSNhanVien();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void bbi_CapNhatKhachHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_KhachHang f = new uc_KhachHang();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }

        private void TKeThuocNhapbarButton_ItemClick(object sender, ItemClickEventArgs e)
        {
            uc_ThongKe_ThuocNhapTheoThang f = new uc_ThongKe_ThuocNhapTheoThang();
            panelControl1.Controls.Clear();
            panelControl1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
        }
    }
}